package jmodel;

import java.security.Principal;
import java.util.LinkedHashSet;
import java.util.Set;

public class Attribute extends MetadataSupport {
    private static final long serialVersionUID = -3971507770343105963L;

    private DataDomain domain;

    // ordered set
    private Set<Constraint> constraints = new LinkedHashSet<Constraint>();

    //nullable owner
    private Object owner;

    public Attribute(String name,Object owner) {
        super(name);
        this.owner = owner;
    }

    public Attribute(String name, Object owner,Principal creater) {
        super(name, creater);

        this.owner = owner;
    }

    public DataDomain getDomain() {
        return domain;
    }

    public void setDomain(DataDomain domain) {
        this.domain = domain;
    }

    public void setConstraints(Set<Constraint> constraints) {
        this.constraints = constraints;
    }

    public Set<Constraint> getConstraints() {
        return constraints;
    }

    @Override
    public boolean equals(Object obj) {
        boolean result = this == obj;
        if (result == false) {
            if (obj instanceof Attribute) {
                Attribute o = (Attribute) obj;
                result = name.equals(o.name) && domain.equals(o.domain) && constraints.equals(o.constraints);
            }
        }

        return result;
    }

    @Override
    public int hashCode() {
        return name.hashCode() & domain.hashCode() & constraints.hashCode();
    }

    public Object getOwner() {
        return owner;
    }

}
